get_directory_depth_offset() {
    local path=${1:?}
    local dirs=${path//[!\/]}
    local depth_array=()
    for (( i=1; i<${#dirs}; ++i )); do
        depth_array+=("../")
    done
    local dirty_str=${depth_array[*]}
    echo "./${dirty_str// /}"
}


get_file_ext() {
    local path=${1:?}
    local filename=
    filename=$(basename -- "$path")
    echo "${filename##*.}"
}


get_ext_to_replace_with_html() {
    local file_type=${1:?}
    if [[ "markdown-smart" == "$file_type" ]]; then
        echo "md"
    elif [[ "markdown" == "$file_type" ]]; then
        echo "md"
    elif [[ "org" == "$file_type" ]]; then
        echo "org"
    else
        echo "Unsupported file_type $file_type" > /dev/stderr
    fi
}


get_working_ext() {
    local file_type=${1:?}
    local path=${2:?}
    local ext_to_replace_with_html
    ext_to_replace_with_html=$(get_ext_to_replace_with_html "$file_type")
    local extension=
    extension=$(get_file_ext "$path")
    if [[ "$extension" != "" ]] && \
           [[ "$extension" == "$ext_to_replace_with_html" ]]; then
        echo "html"
    else
        echo "${extension}"
    fi
}


get_output_file() {
    local file_type=${1:?}
    local path=${2:?}
    local output_dir=${3:-?}

    
    local path_sans_ext="${path%.*}"
    local output_file="${output_dir}/${path_sans_ext#*\/}"

    
    if [[ "" == "$path_sans_ext" ]]; then
        echo "${output_file}$(basename "$path")"
    elif [[ "$path" != "$path_sans_ext" ]]; then
        echo "${output_file}.$(get_working_ext "$file_type" "$path")"
    else
        echo "${output_file}"
    fi
}


# TODO: Remove this and rename get_absolute_path_better to get_absolute_path
get_absolute_path() {
    local current_dir=${1:?}
    local relative_dir=${2:?}
    if [[ "/" == "$current_dir" ]]; then
        echo "${current_dir}$relative_dir"
    else
        echo "${current_dir}/$relative_dir"
    fi
}


get_absolute_path_better() {
    local path=${1:-}
    if [ -d "$path" ]; then
        # shellcheck disable=SC2005
        echo "$(cd "${path}" && pwd || echo "")"
    elif [ -f "$path" ]; then
        # shellcheck disable=SC2005
        echo "$(cd "$(dirname "${path}")" && echo "$(pwd)"/"$(basename "${path}")" || echo "")"
    elif [ -z "$path" ]; then
        >&2 echo "WARNING: ${FUNCNAME[0]}: empty path"
        echo ""
    else
        >&2 echo "ERROR: ${FUNCNAME[0]}: cannot find file or directory: \"${path}\""
        echo ""
    fi
}
